Chapter 4: Writing classes

Driver class ---> has the main method (Client program) Main.java

Helper class (Service providers) Die.java

- Default constructor
- Instance variable vs local variable (scope)
- Visibility modifier
- formal parameters vs actual parameters
- Calling method vs called methods

- Default constructor: 

If you don't provide your own constructor ==> Java creates a default constructor

public Die() {

}

- Instance variable vs local variable:

Location of declaration ===> scope (Area in the code where I can use the variable)

faceValue: can be used anywhere in the class
value: can only be used inside the body owning it (setFaceValue)

Lifecycle of variable: When does Java create faceValue? When does Java create value?

Die die1 = new Die(); // faceValue = 6
Die die2 = new Die(); // faceValue = 6

Everytime a new Die instance/object is created, a new faceValue is created

When does Java create the value variable?

Whenever we call the setFaceValue method, the value is created

die1.setFaceValue(6)

value variable is destroyed before exiting method

Java destroys the instance variable before exiting main

- Visibility modifier: 
public, private, and protected

Encapsulation

Fields/variables
private

Encapsulating the fields within the class


Methods: 
public

Getter method: provides you with read-only access to the instance variable ==> getX
==> accessor methods

Setter methods: allow you to update the value of the instance variable ===> Mutator

- Formal parameters vs actual parameters
Die.java
public void setFaceValue(int value) {

The variable used when creating/defining a method: formal parameter

die1.setFaceValue(6); // actual parameter

- Calling vs called methods

main {

	die1.roll()

}

main is calling roll ===> main (Calling method) and roll (called method)

If the calling method and the called method are defined in two different classes ==> 
We use the called method through an object name

roll {
	getRandVal()
}

roll is calling getRandVal() ===> roll (Calling method) and getRandVal (called )

If the calling and called methods are defined inside the same class =>
Only the name of the called method is needed to use it. 





































